package cumt.kydd.authoringplatform.service;

import cumt.kydd.authoringplatform.bean.History;
import cumt.kydd.authoringplatform.mapper.HistoryMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

import static cumt.kydd.authoringplatform.controller.SaveHistoryController.*;
import static cumt.kydd.authoringplatform.service.UserService.LoginInUser;

@Service
public class SaveHistoryService {
    @Resource
    private HistoryMapper historyMapper;
    public Map<String,Object> createHistory(History history)
    {
        Map<String,Object> resultMap=new HashMap<>();
        history.setName(LoginInUser.getName());
        history.setPassword(LoginInUser.getPassword());
        history.setOriginText(UserOriginText);
        history.setSummary(UserTitle);
        history.setSummary(UserSummary);
        int result = historyMapper.insertHistory(history);
        if(result>0)
        {
            resultMap.put("code",200);
            resultMap.put("message","保存成功，请前往创作历史界面查看！");
        }
        else
        {
            resultMap.put("code",400);
            resultMap.put("message","未知错误，保存失败!");
        }
        return resultMap;
    }
//    public History HistoryQuery(History history){
//        History his = historyMapper.selectHistoryByName(history.getName());
//        return his;
//    }
}

